package com.shopping_back.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopping_back.pojo.entity.MemberOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

@Mapper
public interface MemberOrderMapper extends BaseMapper<MemberOrder> {
    /**
     * 查询用户最新的有效订单（用于图片中的日期显示）
     * @param userId 用户ID
     * @return 订单信息（包含startDate/endDate）
     */
    @Select("SELECT * FROM member_orders WHERE user_id = #{userId} AND status = 1 ORDER BY end_date DESC LIMIT 1")
    MemberOrder selectLatestOrder(@Param("userId") Long userId);

    @Update("UPDATE member_orders SET remind_status = 1 WHERE id = #{orderId}")
    void updateRemindStatus(@Param("orderId") Long orderId);
}
